package se.webbzon.boltzmann.game.object.pickup;

import java.nio.ByteBuffer;

import se.webbzon.boltzmann.environment.AbstractEnvironment;
import se.webbzon.oschi01.friendly.Friendly;
import se.webbzon.oschi01.worldeditor.WorldStaticObjectDeflation;

public class MathNoteDeflation extends WorldStaticObjectDeflation {

	private long id;
	
	private int maxLevel;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new empty math note deflation. **/
	public MathNoteDeflation(int deflationProperties) {
		super(deflationProperties, null);
	}
	
	/** Creates a new math note deflation from an existing math note. **/
	public MathNoteDeflation(int deflationProperties, MathNote note) {
		super(deflationProperties, null, note);
		id = note.getId();
		maxLevel = note.getMaxLevel();
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public void inflate(ByteBuffer buff) {
		super.inflate(buff);
		
		id = buff.getLong();
		maxLevel = buff.getInt();
	}

	@Override public ByteBuffer deflate(int allocate) {
		ByteBuffer buff =  super.deflate(allocate + 12);
		
		buff.putLong(id);
		buff.putInt(maxLevel);
		
		return buff;
	}
	
	/*============================================================
	Friendly Methods
	============================================================*/
	
	/** Creates a new math note from this math note deflation. **/
	@Friendly MathNote createMathNote(AbstractEnvironment env) {
		MathNote note = new MathNote(env,id,maxLevel);
		note.setPosition(getX(), getY(), getZ());
		note.setSize(getWidth(), getHeight(), getDepth());
		note.setRotation(getEX(), getEY(), getEZ(), getAngle());
		
		return note;
	}

}
